import pymysql


def main():
    no = int(input('部门编号'))
    name = input('部门名称')
    loc = input('部门所在地')
    conn = pymysql.connect(host='192.168.84.89', port=3306,
                           user='root', password='Zhjai1@131waaA23',
                           db='hrs', charset='utf8')
    try:
        with conn.cursor() as cursor:
            result = cursor.execute(
                'insert into tb_dept values (%s,%s,%s)‘,(no,name,loc)')
            if result == 1:
                print('添加成功了')
                conn.commit()
    except pymysql.MySQLError as error:
        print(error)
        conn.rollback()
    finally:
        conn.close()


if __name__ == '__main__':
    main()
